#include "informationdialog.h"

InformationDialog::InformationDialog(QWidget *parent) : QDialog(parent)   //构造函数定义，将外部图像作为引用传入
{
    this->resize(QSize(580,360));
    //this->setStyle(QStyleFactory::create("fusion")); //设置所有控件样式为fusion风格
    this->setWindowTitle(tr("Project Information"));

    tableWidget->setFont(QFont("Microsoft Yahei",12));
    tableWidget->setColumnCount(2);
    tableWidget->setIconSize(QSize(20,20));
    tableWidget->setAlternatingRowColors(true);
    tableWidget->setShowGrid(false); //不显示网格线
    tableWidget->setAlternatingRowColors(true); //设置相邻行颜色交替显示
    tableWidget->setColumnWidth(0, 138);  //设置0列宽度
    tableWidget->setColumnWidth(1, this->width()-tableWidget->columnWidth(0)-2); //设置1列宽度
    tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//禁止单元格的编辑功能

    //tableWidget->setStyleSheet("QTableWidget::item:selected{background-color:skyblue }"
                              // "QTableWidget::item:!alternate:!selected{background-color:rgb(232,232,232);}");

    //tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);//点击选中整行，而非选中一个单元格
    //tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(192,212,232); font-size:18px; font-family:'Microsoft YaHei';}");//font:bold;
    tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
    tableWidget->setHorizontalHeaderLabels({tr("Title"),tr("Value")});

    tableWidget->verticalHeader()->setVisible(false); //垂直表头不显示
    tableWidget->verticalHeader()->setDefaultSectionSize(28);//设置所有列的默认行高
    tableWidget->verticalHeader()->setMinimumSectionSize(28);

    tableWidget->setColumnWidth(0, 168);  //设置0列宽度
    tableWidget->setColumnWidth(1, this->width()-tableWidget->columnWidth(0)-2); //设置1列宽度

    QVBoxLayout *vLayout = new QVBoxLayout; //定义垂直布局器
    QHBoxLayout *hLayout = new QHBoxLayout;
    hLayout->setContentsMargins(10, 10, 10, 10); //设置布局器边界宽度
    vLayout->setContentsMargins(0, 0, 0, 0); //设置布局器边界宽度
    this->setLayout(vLayout);//将vLayout设定为本窗口的布局器
    vLayout->setSpacing(0);
    vLayout->addWidget(tableWidget);
    vLayout->addLayout(hLayout);
    hLayout->addStretch();//添加弹簧
    hLayout->addWidget(okButton);
    hLayout->addStretch();//添加弹簧

    connect(okButton, &QPushButton::clicked, this, &InformationDialog::okButtonClicked);//OK按钮点击和处理函数的连接
}

void InformationDialog::okButtonClicked()
{
    this->accept();//OK按钮点击以后发出Accepted返回值
}
